package com.hr.builder;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.FunctionButton;
import com.espirit.eap.pagelayout.ModelField;
import com.hr.DutyRecord;
import com.hr.HrSetting;

@Component
public class DutyRecordBuilder extends ModelBuilderSupport {
	static final String EMPLOYEE = "employee";
	static final String DEPARTMENT = "department";
	static final String DUTYTIME = "dutyTime";
	static final String DEPTIDS = "deptIds";
	static final String TYPE = "type";
	static final String USERID = "userId";
	
	@Override
	public boolean init() {
		return super.setClass(DutyRecord.class, "Duty Record", "考勤记录");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(EMPLOYEE, "Employee", "职员");
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(DEPTIDS, "Department", "部门");
		addModelField(DUTYTIME, "Time", "打卡时间");
		addModelField(TYPE, "Type", "类型");
		addModelField(USERID, "UserId", "UserId");
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
		addButton(FunctionButton.IMPORT);
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(EMPLOYEE, DEPTIDS, TYPE));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(EMPLOYEE,  DEPARTMENT,DUTYTIME, TYPE));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(EMPLOYEE, DUTYTIME, TYPE));
	}
	
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{DEPARTMENT, TYPE});
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
//		if (!isListLayout){
			if (DUTYTIME.equals(name)){
				element.addExProperty("format", HrSetting.TIME_FORMAT);
			}
//		}
		return element;
	}

	
}
